'use strict';
module.exports = {
  /**
   * XXXnameXXX
   * @url client/baidu-ai/kh/write-cts 前端调用的url参数地址
   * data 请求参数
   * @param {String} params1  参数1
   */
  main: async (event) => {
    let {
      data = {}, userInfo, util, filterResponse, originalParam
    } = event;
    let {
      customUtil,
      uniID,
      config,
      pubFun,
      vk,
      db,
      _
    } = util;
    let {
      uid
    } = data;
    let res = {
      code: 0,
      msg: ""
    };
    // 业务逻辑开始-----------------------------------------------------------

    let accessTokenRes = await vk.request({
      url: 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=L1NXAEjaClvMHFPNjROUDd6F&client_secret=eStSSIlNpH9uHp9TRHdgbDZfrbGMSh3O',
      method: "POST",
      header: {
        "content-type": "application/json; charset=utf-8",
      },
      data: {}
    });
    console.log(accessTokenRes)
    let { name, theme, type } = data
    let content = `请以${name}写一首${type}藏头诗，以${theme}为主题，只需要返回诗句即可`
    let ctsRes = await vk.request({
      url: 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro?access_token=' +
        accessTokenRes.access_token,
      method: "POST",
      header: {
        "content-type": "application/json; charset=utf-8",
      },
      data: JSON.stringify({
        "messages": [{
          "role": "user",
          "content": content
        }]
      })
    });
    console.log(ctsRes)
    // 业务逻辑结束-----------------------------------------------------------
    return res;
  }
}